﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GmailMetroNotifier.Client.Common
{
    /// <summary>
    /// Implements extensions to the <see cref="String"/> class
    /// </summary>
    public static class StringExtensions
    {
        /// <summary>
        /// Replaces the format item in a specified string with the string representation
        /// of a corresponding object in a specified array.
        /// </summary>
        /// <param name="instance">A composite format string (see Remarks).</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        /// <returns>A copy of format in which the format items have been replaced by the string
        /// representation of the corresponding objects in args.</returns>
        public static string FormatWith(this string instance, params object[] args)
        {
            return FormatWith(instance, CultureInfo.InvariantCulture, args);
        }

        /// <summary>
        /// Replaces the format item in a specified string with the string representation
        /// of a corresponding object in a specified array. A specified parameter supplies</summary>
        /// culture-specific formatting information.
        /// <param name="instance">A composite format string.</param>
        /// <param name="provider">An object that supplies culture-specific formatting information.</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        /// <returns>A copy of format in which the format items have been replaced by the string
        /// representation of the corresponding objects in args.</returns>
        public static string FormatWith(this string instance, IFormatProvider provider, params object[] args)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            string formattedInstance = instance;

            if (args != null && args.Length > 0)
            {
                formattedInstance = string.Format(provider, instance, args);
            }

            return formattedInstance;
        }
    }
}
